#include<graphics.h>
#include<conio.h>
#pragma comment(lib,"Winmm.lib")

	
	IMAGE img_bc,img_bd1,img_bd2,img_bar_up1,img_bar_up2,img_bar_down1,img_bar_down2;
	int bird_x, bird_y;
	void startup()
	{
		mciSendString("open F:\\background.mp3 alias bkmusic",NULL,0,NULL);
		mciSendString("play bkmusic repeat", NULL, 0, NULL);

		initgraph(350, 600);
		loadimage(&img_bc, _T("F:\\background.jpg"));
		loadimage(&img_bd1, _T("F:\\bird1.jpg"));
		loadimage(&img_bd2, _T("F:\\bird2.jpg"));
		loadimage(&img_bar_down1, _T("F:\\bar_down1.gif"));
		loadimage(&img_bar_down2, _T("F:\\bar_down2.gif"));
		loadimage(&img_bar_up1, _T("F:\\bar_up1.gif"));
		loadimage(&img_bar_up2, _T("F:\\bar_up2.gif"));
		bird_x = 50;
		bird_y = 200;
		BeginBatchDraw();
	}
	void show()
	{
		putimage(0, 0, &img_bc);
		putimage(bird_x,bird_y,&img_bd1,NOTSRCERASE);
		putimage(bird_x, bird_y, &img_bd2,SRCINVERT);
		putimage(150, -300, &img_bar_up1, NOTSRCERASE);
		putimage(150, -300, &img_bar_up2, SRCINVERT);
		putimage(150, 400, &img_bar_down1, NOTSRCERASE);
		putimage(150, 400, &img_bar_down2, SRCINVERT);
		FlushBatchDraw();
		Sleep(50);
	}
	void updatawithoutinput()
	{
		if (bird_y < 580)
		{
			bird_y += 3;
		}
	}
	void updatawithinput()
	{
		char input;
		if (_kbhit())
		{
			input = _getch();
			if (input==' '&&bird_y > 20)
			{
				bird_y -= 60;
				mciSendString("close jpmusic ", NULL, 0, NULL);
				mciSendString("open F:\\Jump.mp3 alias jpmusic", NULL, 0, NULL);
				mciSendString("play jpmusic", NULL, 0, NULL);
			}
		}
	}
	void gameover()
	{
		EndBatchDraw();
		_getch();
		closegraph();
	}
int main()
	{
		startup();
		while (1)
		{
			show();
			updatawithoutinput();
			updatawithinput();

		}
		gameover();
		return 0;
	}
	
